package com.homegoods.area.presenter;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.homegoods.area.AreaApiUtils;
import com.homegoods.area.model.AreaModel;
import com.homegoods.area.ui.view.IAreaView;
import com.kedll.library.mvp.BasePresenter;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.functions.Consumer;


/**
 * @author QiQi
 */
public class AreaPresenter extends BasePresenter<IAreaView> {

    public AreaPresenter(IAreaView view) {
        super(view);
    }

    public void getArea() {
        AreaApiUtils.getAreaList(new Consumer<List<AreaModel>>() {
            @Override
            public void accept(List<AreaModel> areaBeans) throws Exception {
                String s = JSON.toJSONString(areaBeans);

                mView.setArea(0, areaBeans);
            }
        }, throwable -> Log.d("zhengshibo3", "getArea: errorrrrrr  " + throwable.toString()));
      /* List<AreaModel> lists = new ArrayList<>();
       AreaModel model = new AreaModel();
       model.setAreaName("北京");
       model.setId("1");
       model.setRid("20");
       model.setItems("朝阳区");
       model.setItems("海淀区");
        AreaModel model2 = new AreaModel();
        model2.setAreaName("天津");
        model2.setId("2");
        model2.setRid("22");
        model2.setItems("河东区");
        model2.setItems("河西区");
        lists.add(model);
        lists.add(model2);
        mView.setArea(0, lists);*/

    }

    public void loadArea(int index, String items) { //未执行
        List<AreaModel> beans = JSON.parseArray(items, AreaModel.class);
        if (beans != null) {
            mView.setArea(index, beans);
        }
    }

}